﻿using Microsoft.Extensions.DependencyInjection;

using PLCS.Domain.Data;

using Volo.Abp.DependencyInjection;

namespace PLCS.EntityFrameworkCore.EntityFrameworkCore
{
    public class EntityFrameworkCorePLCSDbSchemaMigrator
        : IPLCSDbSchemaMigrator, ITransientDependency
    {
        private readonly IServiceProvider _serviceProvider;

        public EntityFrameworkCorePLCSDbSchemaMigrator(
            IServiceProvider serviceProvider)
        {
            _serviceProvider = serviceProvider;
        }

        public async Task MigrateAsync()
        {
            await _serviceProvider
                .GetRequiredService<PLCSDbContext>()
                .Database
                .MigrateAsync();
        }
    }
}